WORKSHOP5
/*
* Cay S. Horstmann & Gary Cornell, Core Java
* Published By Sun Microsystems Press/Prentice-Hall
* Copyright (C) 1997 Sun Microsystems Inc.
* All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for NON-COMMERCIAL purposes
* and without fee is hereby granted provided that this
* copyright notice appears in all copies.
*
* THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR
* WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS
* AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED
* BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*/
/* Modified by Warakorn */
/**
* @version 1.00 07 Feb 1996
* @author Cay Horstmann
*/
import java.util.*;
import corejava.*;
public class ExecutiveTest
{ public static void main(String[] args)
{ Employee[] staff = new Employee[3];
staff[0] = new Employee("Little Bird", 35000,
new Day(1999,10,1));
staff[1] = new Manager("Miss K", 200000,
new Day(1990,12,15),"Miss Glasses");
staff[2] = new Executive("Warakon Kunawong", 120000,
new Day(1998,3,15),"Little Bird" , "Saan");
int i;
for (i = 0; i < 3; i++) staff[i].raiseSalary(5);
for (i = 0; i < 3; i++) staff[i].print();
}
}
class Employee
{ public Employee(String n, double s, Day d)
{ name = n;
salary = s;
hireDay = d;
}
public void print()
{ System.out.println(name + " " + (int)salary + " "
+ hireYear());
}
public void raiseSalary(double byPercent)
{ salary *= 1 + byPercent / 100;
}
public int hireYear()
{ return hireDay.getYear();
}
protected String name;
protected double salary;
protected Day hireDay;
}
class Manager extends Employee
{ public Manager(String n, double s, Day d)
{ super(n, s, d);
secretaryName = "";
}
public Manager(String n, double s, Day d, String sName)
{ super(n, s, d);
secretaryName = sName;
}
public void raiseSalary(double byPercent)
{ // add 1/2% bonus for every year of service
Day today = new Day();
double bonus = 0.5 * (today.getYear() - hireYear());
super.raiseSalary(byPercent + bonus);
}
public void print()
{ System.out.println(name + " " + (int)salary + " "
+ hireYear()+" "+ secretaryName);
}
public void setSecretaryName(String n)
{ secretaryName = n;
}
public String getSecretaryName()
{ return secretaryName;
}
protected String secretaryName;
}
class Executive extends Manager
{
public Executive(String n, double s, Day d)
{ super(n, s, d);
driverName = "";
}
public Executive(String n, double s, Day d, String sName,String dName)
{ super(n, s, d, sName);
driverName = dName;
}
public void raiseSalary(double byPercent)
{ // add 3/4% bonus for every year of service
Day today = new Day();
double bonus = 0.75 * (today.getYear() - hireYear());
super.raiseSalary(byPercent + bonus);
}
public void print()
{ System.out.println(name + " " + (int)salary + " "
+ hireYear()+" "+ secretaryName+ " " +driverName);
}
public void setDriverName(String n)
{ driverName = n;
}
public String getDriverName()
{ return driverName;
}
private String driverName;
};
===============================
result
===============================
Little Bird 36750 1999
Miss K 220000 1990 Miss Glasses
Warakon Kunawong 129000 1998 Little Bird Saan